package com.somsoft.bzfk;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;

import com.pckg.p.PAManager;
import com.somsoft.bzfk.common.MyApplication;
import com.somsoft.bzfk.db.Service;
import com.umeng.analytics.MobclickAgent;

public class WelcomeActivity extends Activity implements OnClickListener {
	DisplayMetrics dm;
	ImageButton btnNewGame;
	ImageButton btnContinue;
	ImageButton btnExit;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		MyApplication.getInstance().addActivity(this);
		dm = new DisplayMetrics();
		getWindowManager().getDefaultDisplay().getMetrics(dm);
		setContentView(R.layout.main);
		btnNewGame = (ImageButton) findViewById(R.id.btnNewGame);
		btnContinue = (ImageButton) findViewById(R.id.btnContinue);
		btnExit = (ImageButton) findViewById(R.id.btnExit);

		btnNewGame.setOnClickListener(this);
		btnContinue.setOnClickListener(this);
		btnExit.setOnClickListener(this);

		PAManager pm = PAManager.getInstance(this);
		// 设置cooId
		pm.setCooId(this, "e0eb7217d8d24ebda56ad28e3152dbfb");
		// 设置channelId
//		pm.setChannelId(this, "k-hiapk");//安卓市场
//		pm.setChannelId(this, "k-gfan");//机锋市场
		pm.setChannelId(this, "k-appchina");
		// 接收push
		pm.receiveMessage(this, true);
	}

	@Override
	public void onClick(View v) {
		int id = v.getId();
		Intent it = new Intent(this, GameActivity.class);
		if (R.id.btnNewGame == id) {
			it.putExtra("lv", 1);
			startActivity(it);
		} else if (R.id.btnContinue == id) {
			Service s = new Service(this);
			it.putExtra("lv", s.getLevel());
			startActivity(it);
		} else if (R.id.btnExit == id) {
			MyApplication.getInstance().exit();
		}
	}
	
	public void onResume() {
	    super.onResume();
	    MobclickAgent.onResume(this);
	}
	public void onPause() {
	    super.onPause();
	    MobclickAgent.onPause(this);
	}
}
